package com.zulu.karaoke.gui.custom;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.zulu.karaoke.R;

public class CustomProgressDialog {

	ProgressDialog progressDialog;

	public CustomProgressDialog(Context context, String mess) {
		progressDialog = ProgressDialog.show(context, null, null);
		View view = LayoutInflater.from(context).inflate(
				R.layout.custom_progress_dialog_layout, null);
		TextView tvContextMess = (TextView) view
				.findViewById(R.id.tv_content_mess);
		tvContextMess.setText(mess);
		progressDialog.setContentView(view);
	}
	
	public void incrementProgressBy(int sec) {
		progressDialog.incrementProgressBy(sec);
	}
	
	public CustomProgressDialog(Context context, String mess, final Handler handle) {
		View view = LayoutInflater.from(context).inflate(
				R.layout.custom_progress_dialog_layout, null);
		TextView tvContextMess = (TextView) view
				.findViewById(R.id.tv_content_mess);
		tvContextMess.setText(mess);
		progressDialog.setContentView(view);
		progressDialog.setProgress(0);
		progressDialog.setMax(100);
		progressDialog = ProgressDialog.show(context, null, null);
		new Thread(new Runnable() {
			
			@Override
			public void run() {
				try
                {
                      while(progressDialog.getProgress()<=progressDialog.getMax())
                      {
                            Thread.sleep(1000);
                            handle.sendMessage(handle.obtainMessage());
                            if(progressDialog.getProgress()==progressDialog.getMax())
                            {
                            	progressDialog.dismiss();
                            }
                      }
                }catch(Exception e){
                	
                }
			}
		});
	}

	public void hideDialog() {
		progressDialog.dismiss();
	}
}
